package com.ctech.wsgen.model;

import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.Locale;

public class Item  {

	private int id;
	private String partNum;
	private String vendorName;
	private String description;
	private BigDecimal price;
	private String fileName;

	public Item(int id, String vendorName, String partNum, String description, 
			BigDecimal price, String fileName) {
		super();
		this.id = id;
		this.vendorName = vendorName;
		this.partNum = partNum;
		this.description = description;
		this.price = price;
		this.setFileName(fileName);
	}

	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getPartNum() {
		return partNum;
	}
	public void setPartNum(String partNum) {
		this.partNum = partNum;
	}
	public String getVendorName() {
		return vendorName;
	}
	public void setVendorName(String name) {
		this.vendorName = name;
	}
	public String getDescription() {
		return description == null ? "" : description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public BigDecimal getPrice() {
		return price;
	}
	public String getPriceFormatted() {
		NumberFormat nFormat = NumberFormat.getCurrencyInstance(Locale.US);
		if(price == null) {
			return "Call For Price";
		}
		return nFormat.format(price.doubleValue());
	}
	public void setPrice(BigDecimal price) {
		this.price = price;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public String getFileName() {
		return fileName;
	}
	
	public Item getAsItem() {
		return new Item(getId(), getVendorName(), getPartNum(), getDescription(), getPrice(), getFileName()); 
	}
	
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("Item [description=");
		builder.append(description);
		builder.append(", fileName=");
		builder.append(fileName);
		builder.append(", id=");
		builder.append(id);
		builder.append(", partNum=");
		builder.append(partNum);
		builder.append(", price=");
		builder.append(price);
		builder.append(", vendorName=");
		builder.append(vendorName);
		builder.append("]");
		return builder.toString();
	}

	
}
